package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.sys.CommonalityUrlCollection;
import com.prs.crm.service.sys.CommonalityUrlCollectionService;

public class CommonalityUrlCollectionAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private CommonalityUrlCollection commonalityUrlCollection;
	private CommonalityUrlCollectionService commonalityUrlCollectionService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public CommonalityUrlCollection getCommonalityUrlCollection() {
		return commonalityUrlCollection;
	}
	public void setCommonalityUrlCollection(
			CommonalityUrlCollection commonalityUrlCollection) {
		this.commonalityUrlCollection = commonalityUrlCollection;
	}
	public CommonalityUrlCollectionService getCommonalityUrlCollectionService() {
		return commonalityUrlCollectionService;
	}
	public void setCommonalityUrlCollectionService(
			CommonalityUrlCollectionService commonalityUrlCollectionService) {
		this.commonalityUrlCollectionService = commonalityUrlCollectionService;
	}
	@Action("listCommonUrlCollection")
	public String listCommonUrlCollection(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(CommonalityUrlCollection.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getCommonalityUrlCollectionService().listByPage(criteria, pagination));
		return SUCCESS;
	} 
	
	@Action("editCommonUrlCollection")
	public String editCommonUrlCollection(){
		if(ids!=null){
			this.commonalityUrlCollection=this.getCommonalityUrlCollectionService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value="saveCommonUrlCollection", results={
			@Result(name="success",type="redirect",location="listCommonUrlCollection"),
			@Result(name="error",type="chain",location="editCommonUrlCollection")
	})
	public String saveCommonUrlCollection(){
		this.getCommonalityUrlCollectionService().save(commonalityUrlCollection);
		if(commonalityUrlCollection.getName()==null||"".equals(commonalityUrlCollection.getName().trim())){
			commonalityUrlCollection.setName(commonalityUrlCollection.getUrl());
		}
		this.getCommonalityUrlCollectionService().submit(commonalityUrlCollection);
		return SUCCESS;
	}
	@Action(value="saveCommonUrlCollections", results={
			@Result(name="success",type="redirect",location="editCommonUrlCollection"),
			@Result(name="error",type="chain",location="editCommonUrlCollection")
	})
	public String saveCommonUrlCollections(){
		this.getCommonalityUrlCollectionService().save(commonalityUrlCollection);
		if(commonalityUrlCollection.getName()==null||"".equals(commonalityUrlCollection.getName().trim())){
			commonalityUrlCollection.setName(commonalityUrlCollection.getUrl());
		}
		this.getCommonalityUrlCollectionService().submit(commonalityUrlCollection);
		return SUCCESS;
	}
	@Action(value="removeCommonUrlCollection", results={
			@Result(name="success",type="redirect",location="listCommonUrlCollection"),
			@Result(name="error",type="chain",location="listCommonUrlCollection")
	})
	public String removeCommonUrlCollection(){
		if(ids!=null){
			this.commonalityUrlCollection=this.getCommonalityUrlCollectionService().get(ids[0]);
		}
		this.getCommonalityUrlCollectionService().batchRemove(ids);
		return SUCCESS;
	}
}
